﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
namespace GameEditor.Common
{
    public class CustomOpenFileDialog: System.IDisposable
    {
        #region IDisposable Members

        public void Dispose()
        {
            dialog.Dispose();
        }

        #endregion

        protected OpenFileDialog dialog = new OpenFileDialog();


        //
        // Summary:
        //     Resets all properties to their default values.
        public void Reset()
        {
            dialog.Reset();
        }
        //
        // Summary:
        //     Runs a common dialog box with a default owner.
        //
        // Returns:
        //     System.Windows.Forms.DialogResult.OK if the user clicks OK in the dialog
        //     box; otherwise, System.Windows.Forms.DialogResult.Cancel.
        public DialogResult ShowDialog()
        {
            using (DirectoryScope ds = new DirectoryScope())
            {
                return dialog.ShowDialog();
            }
        }
        //
        // Summary:
        //     Runs a common dialog box with the specified owner.
        //
        // Parameters:
        //   owner:
        //     Any object that implements System.Windows.Forms.IWin32Window that represents
        //     the top-level window that will own the modal dialog box.
        //
        // Returns:
        //     System.Windows.Forms.DialogResult.OK if the user clicks OK in the dialog
        //     box; otherwise, System.Windows.Forms.DialogResult.Cancel.
        public DialogResult ShowDialog(IWin32Window owner)
        {
            using (DirectoryScope ds = new DirectoryScope())
            {
                return dialog.ShowDialog(owner);
            }
        }

        // Summary:
        //     Gets or sets a value indicating whether the dialog box displays a warning
        //     if the user specifies a file name that does not exist.
        //
        // Returns:
        //     true if the dialog box displays a warning when the user specifies a file
        //     name that does not exist; otherwise, false. The default value is true.
        [DefaultValue(true)]
        public bool CheckFileExists { get {return dialog.CheckFileExists;} set {dialog.CheckFileExists=value;} }
        //
        // Summary:
        //     Gets or sets a value indicating whether the dialog box allows multiple files
        //     to be selected.
        //
        // Returns:
        //     true if the dialog box allows multiple files to be selected together or concurrently;
        //     otherwise, false. The default value is false.
        [DefaultValue(false)]
        public bool Multiselect { get {return dialog.Multiselect;} set {dialog.Multiselect=value;} }
        //
        // Summary:
        //     Gets or sets a value indicating whether the read-only check box is selected.
        //
        // Returns:
        //     true if the read-only check box is selected; otherwise, false. The default
        //     value is false.
        [DefaultValue(false)]
        public bool ReadOnlyChecked { get {return dialog.ReadOnlyChecked;} set {dialog.ReadOnlyChecked=value;} }
        //
        // Summary:
        //     Gets the file name and extension for the file selected in the dialog box.
        //     The file name does not include the path.
        //
        // Returns:
        //     The file name and extension for the file selected in the dialog box. The
        //     file name does not include the path. The default value is an empty string.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Browsable(false)]
        public string SafeFileName { get { return dialog.SafeFileName; } }
        //
        // Summary:
        //     Gets an array of file names and extensions for all the selected files in
        //     the dialog box. The file names do not include the path.
        //
        // Returns:
        //     An array of file names and extensions for all the selected files in the dialog
        //     box. The file names do not include the path. If no files are selected, an
        //     empty array is returned.
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string[] SafeFileNames { get { return dialog.SafeFileNames; } }
        //
        // Summary:
        //     Gets or sets a value indicating whether the dialog box contains a read-only
        //     check box.
        //
        // Returns:
        //     true if the dialog box contains a read-only check box; otherwise, false.
        //     The default value is false.
        [DefaultValue(false)]
        public bool ShowReadOnly { get {return dialog.ShowReadOnly;} set {dialog.ShowReadOnly=value;} }

        // Summary:
        //     Opens the file selected by the user, with read-only permission. The file
        //     is specified by the System.Windows.Forms.FileDialog.FileName property.
        //
        // Returns:
        //     A System.IO.Stream that specifies the read-only file selected by the user.
        //
        // Exceptions:
        //   System.ArgumentNullException:
        //     The file name is null.
        public System.IO.Stream OpenFile()
        {
            return dialog.OpenFile();
        }

        // Summary:
        //     Gets or sets a value indicating whether the dialog box automatically adds
        //     an extension to a file name if the user omits the extension.
        //
        // Returns:
        //     true if the dialog box adds an extension to a file name if the user omits
        //     the extension; otherwise, false. The default value is true.
        [DefaultValue(true)]
        public bool AddExtension { get {return dialog.AddExtension;} set {dialog.AddExtension=value;} }
        //
        // Summary:
        //     Gets or sets a value indicating whether this System.Windows.Forms.FileDialog
        //     instance should automatically upgrade appearance and behavior when running
        //     on Windows Vista.
        //
        // Returns:
        //     true if this System.Windows.Forms.FileDialog instance should automatically
        //     upgrade appearance and behavior when running on Windows Vista; otherwise,
        //     false. The default is true.
        [DefaultValue(true)]
        public bool AutoUpgradeEnabled { get {return dialog.AutoUpgradeEnabled;} set {dialog.AutoUpgradeEnabled=value;} }
        //
        // Summary:
        //     Gets or sets a value indicating whether the dialog box displays a warning
        //     if the user specifies a path that does not exist.
        //
        // Returns:
        //     true if the dialog box displays a warning when the user specifies a path
        //     that does not exist; otherwise, false. The default value is true.
        [DefaultValue(true)]
        public bool CheckPathExists { get {return dialog.CheckPathExists;} set {dialog.CheckPathExists=value;} }
        //
        // Summary:
        //     Gets the custom places collection for this System.Windows.Forms.FileDialog
        //     instance.
        //
        // Returns:
        //     The custom places collection for this System.Windows.Forms.FileDialog instance.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Browsable(false)]
        public FileDialogCustomPlacesCollection CustomPlaces { get { return dialog.CustomPlaces; } }
        //
        // Summary:
        //     Gets or sets the default file name extension.
        //
        // Returns:
        //     The default file name extension. The returned string does not include the
        //     period. The default value is an empty string ("").
        [DefaultValue("")]
        public string DefaultExt { get {return dialog.DefaultExt;} set {dialog.DefaultExt=value;} }
        //
        // Summary:
        //     Gets or sets a value indicating whether the dialog box returns the location
        //     of the file referenced by the shortcut or whether it returns the location
        //     of the shortcut (.lnk).
        //
        // Returns:
        //     true if the dialog box returns the location of the file referenced by the
        //     shortcut; otherwise, false. The default value is true.
        [DefaultValue(true)]
        public bool DereferenceLinks { get {return dialog.DereferenceLinks;} set {dialog.DereferenceLinks=value;} }
        //
        // Summary:
        //     Gets or sets a string containing the file name selected in the file dialog
        //     box.
        //
        // Returns:
        //     The file name selected in the file dialog box. The default value is an empty
        //     string ("").
        [DefaultValue("")]
        public string FileName { get {return dialog.FileName;} set {dialog.FileName=value;} }
        //
        // Summary:
        //     Gets the file names of all selected files in the dialog box.
        //
        // Returns:
        //     An array of type System.String, containing the file names of all selected
        //     files in the dialog box.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Browsable(false)]
        public string[] FileNames { get { return dialog.FileNames; } }
        //
        // Summary:
        //     Gets or sets the current file name filter string, which determines the choices
        //     that appear in the "Save as file type" or "Files of type" box in the dialog
        //     box.
        //
        // Returns:
        //     The file filtering options available in the dialog box.
        //
        // Exceptions:
        //   System.ArgumentException:
        //     Filter format is invalid.
        [DefaultValue("")]
        [Localizable(true)]
        public string Filter { get {return dialog.Filter;} set {dialog.Filter=value;} }
        //
        // Summary:
        //     Gets or sets the index of the filter currently selected in the file dialog
        //     box.
        //
        // Returns:
        //     A value containing the index of the filter currently selected in the file
        //     dialog box. The default value is 1.
        [DefaultValue(1)]
        public int FilterIndex { get {return dialog.FilterIndex;} set {dialog.FilterIndex=value;} }
        //
        // Summary:
        //     Gets or sets the initial directory displayed by the file dialog box.
        //
        // Returns:
        //     The initial directory displayed by the file dialog box. The default is an
        //     empty string ("").
        [DefaultValue("")]
        public string InitialDirectory { get {return dialog.InitialDirectory;} set {dialog.InitialDirectory=value;} }
        //
        // Summary:
        //     Gets or sets a value indicating whether the dialog box restores the current
        //     directory before closing.
        //
        // Returns:
        //     true if the dialog box restores the current directory to its original value
        //     if the user changed the directory while searching for files; otherwise, false.
        //     The default value is false.
        [DefaultValue(false)]
        public bool RestoreDirectory { get {return dialog.RestoreDirectory;} set {dialog.RestoreDirectory=value;} }
        //
        // Summary:
        //     Gets or sets a value indicating whether the Help button is displayed in the
        //     file dialog box.
        //
        // Returns:
        //     true if the dialog box includes a help button; otherwise, false. The default
        //     value is false.
        [DefaultValue(false)]
        public bool ShowHelp { get {return dialog.ShowHelp;} set {dialog.ShowHelp=value;} }
        //
        // Summary:
        //     Gets or sets whether the dialog box supports displaying and saving files
        //     that have multiple file name extensions.
        //
        // Returns:
        //     true if the dialog box supports multiple file name extensions; otherwise,
        //     false. The default is false.
        [DefaultValue(false)]
        public bool SupportMultiDottedExtensions { get {return dialog.SupportMultiDottedExtensions;} set {dialog.SupportMultiDottedExtensions=value;} }
        //
        // Summary:
        //     Gets or sets the file dialog box title.
        //
        // Returns:
        //     The file dialog box title. The default value is an empty string ("").
        [Localizable(true)]
        [DefaultValue("")]
        public string Title { get {return dialog.Title;} set {dialog.Title=value;} }
        //
        // Summary:
        //     Gets or sets a value indicating whether the dialog box accepts only valid
        //     Win32 file names.
        //
        // Returns:
        //     true if the dialog box accepts only valid Win32 file names; otherwise, false.
        //     The default value is true.
        [DefaultValue(true)]
        public bool ValidateNames { get {return dialog.ValidateNames;} set {dialog.ValidateNames=value;} }

        //
        // Summary:
        //     Provides a string version of this object.
        //
        // Returns:
        //     A string version of this object.
        public override string ToString()
        {
            return dialog.ToString();
        }

    }
}
